
typedef struct{
    char *buffer;
    int buff_len;

    int data_begin; //data begin index;
    int data_len;
}car_hw_buffer_t;

class CarHardwareBase{
public:
    virtual int HardwareOpen(car_hardware_param_t* param);
    virtual int HardwareClose();
    virtual int HardwareSetParam(car_hardware_param_t* param);
    virtual int HardwareGetParam(car_hardware_param_t* param);
    virtual int HardwareSend(char* src,int len);            //send data to car
    virtual int HardwareRead(char* outbuf,int outbuf_len,int maxtime);  //read datas from car


private:
    int MemoryAlloc(char **out,int outsize,char **in,int insize);
    void MemoryFree(char *out,char *in);

    int init(car_hardware_param_t* param,ProtocolBase* pro);
    void exit();
    int start();
    int stop();

    int setpara(car_hardware_param_t* param);
    int getpara(car_hardware_param_t* param);

    ProtocolBase* mProto;
    int iMaxPacketLength;
    int iMinPacketLength;

    /** Thread about */
#define CN_CAR_THREAD_ST_NONO 					0
#define CN_CAR_THREAD_ST_LOOP						1
#define CN_CAR_THREAD_ST_WAIT_EXIT			3

		void CarHWThreadLoop(void *);
		int ReadHWDatasToApp();
		int SendAppPacketToHW();
		pthread_t mHWThread = NULL;

		int iMaxReadHWMsTime = 500;//When Device read datas,max allow delate time is 500ms
    int iHWNewReadedCount;

    car_hw_buffer_t mOutBuf;
    car_hw_buffer_t mInBuf;
		int Bufferfree();
    int BufferInit();

    int mState=0;
};


